package com.myz.service.order;

import brave.sampler.Sampler;
import com.spring4all.swagger.EnableSwagger2Doc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 开启服务发现 EnableDiscoveryClient
 *
 * @author maoyz0621
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
@EnableSwagger2Doc
public class ServiceOrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceOrderApplication.class, args);
    }

    /**
     * rest使用别名访问，依赖ribbon负载均衡，否则：java.net.UnknownHostException: SERVICE-MEMBER
     * 开启客户端负载均衡@LoadBalanced
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public Sampler defaultSampler() {
        return Sampler.ALWAYS_SAMPLE;
    }
}
